<?php
	class Order_offline_course extends MY_controller{

		function __construct(){
			parent::__construct();
		}

		function index($school_id = 0, $order_status = 9, $start_time = 0, $end_time = 0, $limit = 0)
		{
			$post_data = $this->input->post();
			if($post_data){
				$school_id = !empty($post_data['school_id']) ? $post_data['school_id'] : 0;
				$order_status = isset($post_data['order_status']) ? $post_data['order_status'] : 9;
				$start_time = !empty($post_data['start_time']) ? $post_data['start_time'] : 0;
				$end_time = !empty($post_data['end_time']) ? $post_data['end_time'] : 0;
			}
			
			//获取网校
			$this->load->model('Schools');
			$schools = $this->Schools->get_school_all();
			$this->smarty->assign("schools", $schools);

			//获取订单
			$this->load->model('Order_model');
			$conditions['school_id'] = $school_id;
			$conditions['order_status'] = $order_status;
			$conditions['start_time'] = $start_time;
			$conditions['end_time'] = $end_time;
			$orders = $this->Order_model->get_order_list($limit,$this->offset,$conditions);
			$this->smarty->assign("orders", $orders['result']);

			$this->smarty->assign("current_url", "/order_offline_course");

			$this->load->library('pagination');
			$page_config['base_url'] = '/order_offline_course/index/'.$school_id.'/'.$order_status.'/'.$start_time.'/'.$end_time;
			$page_config['total_rows'] = $orders['count'];
			$page_config['per_page'] = $this->offset;
			$page_config['uri_segment'] = 8;
			$this->pagination->initialize($page_config);
			$pagination = $this->pagination->create_links();

			$this->smarty->assign("conditions", $conditions);
			$this->smarty->assign("pagination", $pagination);
			$this->smarty->assign("action", "网校订单列表");
			$this->smarty->assign("menu", "course");
			$this->smarty->display("order/order_offline_course.html");
		}

		function get_amount(){
			$post_data = $this->input->post();
			if($post_data){
				$school_id = !empty($post_data['school_id']) ? $post_data['school_id'] : 0;
				$order_status = isset($post_data['order_status']) ? $post_data['order_status'] : 9;
				$start_time = !empty($post_data['start_time']) ? $post_data['start_time'] : 0;
				$end_time = !empty($post_data['end_time']) ? $post_data['end_time'] : 0;
			}
			$this->load->model('Order_model');
			$conditions['school_id'] = $school_id;
			$conditions['order_status'] = $order_status;
			$conditions['start_time'] = $start_time;
			$conditions['end_time'] = $end_time;
			$result = $this->Order_model->get_order_total_amount($conditions);
			echo number_format($result['total_amount'], 2, '.', '');
		}
}